package com.basker.pisces.domain.validation.validator;

import com.basker.pisces.domain.command.CommandExecuteContext;
import com.basker.pisces.domain.entity.meta.Entity;
import com.basker.pisces.domain.validation.IDependOnValidation;
import com.basker.pisces.domain.validation.meta.Validation;

/**
 * 带有验证配置对象({@link Validation})的验证器
 *
 * @param <TValidation>
 * @author hangwen
 */
public abstract class AbstractConfigValidator<TValidation extends Validation>
        implements ICommandValidator, IDependOnValidation {

    private Validation validation;
    private CommandExecuteContext context;

    @Override
    public final CommandExecuteContext getContext() {
        return context;
    }

    @Override
    public Entity getEntity() {
        return this.context.getEntity();
    }

    @Override
    @SuppressWarnings("unchecked")
    public TValidation getValidation() {
        return (TValidation) validation;
    }

    @Override
    public void setContext(CommandExecuteContext context) {
        this.context = context;
    }

    @Override
    public void setValidation(Validation validation) {
        this.validation = validation;
    }
}
